package ModelLayer;
import java.util.ArrayList;
//The purpose of using an ArrayList is to store the DVD instances in the Register.
public class DvdRegister
{
    private ArrayList<DVD> dvdCollection;
    private static DvdRegister instance;
   
    /** CONSTRUCTORS */
    public DvdRegister()
    {
        dvdCollection = new ArrayList<DVD>();
    }
    
    /** ACCESSORS */
    public static DvdRegister getInstance()
    {
        if(instance == null)
        {
            instance = new DvdRegister();
        }
        return instance;
    }

    public ArrayList<DVD> findDVD()
    //Shows our DVD collection.
    {
        return dvdCollection;
    }
    
    /** MUTATORS */
        public void addDVD(String dvdId, String title, String artist, String publicationDate)
    //Add a new DVD to our collection.
    {
        dvdCollection.add(new DVD(dvdId, title, artist, publicationDate));
    }
    
    public void removeDVD(String title){
        dvdCollection.remove(findDVD(title));
    }
    
    public void updateDVD(DVD myDVD, String dvdId, String title, String artist, String publicationDate)
    //Updates details of a DVD in our collection.
    {
        myDVD.setDvdId(dvdId);
        myDVD.setTitle(title);
        myDVD.setArtist(artist);
        myDVD.setPublicationDate(publicationDate);
    }
    
    public DVD findDVD(String title){
        int i = 0;
        boolean found = false;
        while(!found&&dvdCollection.size()>i){
            if(title.equals(dvdCollection.get(i).getTitle())){
                found = true; 
            }
            else{
                i++;
            }
        }
        if(!found){
            return null;
        }
        return dvdCollection.get(i);
    }
}